<template>
  <AmBaseTable :schema="modelSchema"
               :dataSource="data"
               @pagination="getList"
               :operations="[
                  {
                    label: '新增',
                    auth: ['am:amArchive:add'],
                    buttonProps: {
                      type: 'primary',
                      icon: 'el-icon-plus',
                    }
                  },
                  {
                    label: '导出',
                    auth: ['am:amArchive:export'],
                    buttonProps: {
                      type: 'warning',
                      icon: 'el-icon-download',
                    }
                  },
                ]"
               :actions="[
                  {
                    label: '修改',
                    auth: ['am:description:edit'],
                    clickCB: this.testActCB,
                    buttonProps: {
                      icon: 'el-icon-edit',
                    }
                  },
                  {
                    label: '删除',
                    auth: ['am:description:remove'],
                    buttonProps: {
                      icon: 'el-icon-delete',
                    }
                  },
                ]">
<!--    <template v-slot:column-id="scope">{{ scope }}</template>-->
  </AmBaseTable>
</template>

<script>
import { listDescription, getDescription, delDescription, addDescription, updateDescription } from "@/api/am/description";
import AmBaseTable from "../../../components/AmComp/AmBaseTable.vue";
import {modelSchema} from "../amDescription/model";

export default {
  name: "Description",
  components: {AmBaseTable},
  data() {
    return {
      modelSchema,
      data: [
        {
          id: '123',
          archiveTime: '2023-11-28',
        }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 档案著录表格数据
      descriptionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fileCode: null,
        classificationCode: null,
        archiveTime: null,
        groupId: null,
        title: null,
        keyword: null,
        notes: null,
        cabinetId: null,
        fondCode: null,
        saveDate: null,
        dispatchNumber: null,
        filingTime: null,
        filingPerson: null,
        startTime: null,
        endTime: null,
        extendedIndex: null,
        brStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fileCode: [
          { required: true, message: "案卷号不能为空", trigger: "blur" }
        ],
        classificationCode: [
          { required: true, message: "档案类别不能为空", trigger: "blur" }
        ],
        archiveTime: [
          { required: true, message: "归档时间不能为空", trigger: "blur" }
        ],
        groupId: [
          { required: true, message: "档案级别不能为空", trigger: "blur" }
        ],
        title: [
          { required: true, message: "提名不能为空", trigger: "blur" }
        ],
        cabinetId: [
          { required: true, message: "档案柜不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    testActCB(row) {
      console.log(row);
    },
    /** 查询档案著录列表 */
    getList() {
      this.loading = true;
      listDescription(this.queryParams).then(response => {
        this.descriptionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fileCode: null,
        classificationCode: null,
        archiveTime: null,
        groupId: null,
        title: null,
        keyword: null,
        notes: null,
        cabinetId: null,
        fondCode: null,
        saveDate: null,
        dispatchNumber: null,
        filingTime: null,
        filingPerson: null,
        startTime: null,
        endTime: null,
        extendedIndex: null,
        brStatus: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加档案著录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDescription(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改档案著录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDescription(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDescription(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除档案著录编号为"' + ids + '"的数据项？').then(function() {
        return delDescription(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('am/description/export', {
        ...this.queryParams
      }, `description_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
